//
//  CommonParameterManager.m
//  atm
//
//  Created by Topsun on 15/11/26.
//  Copyright © 2015年 Xizi. All rights reserved.
//

#import "CommonParameterManager.h"
#import <sys/utsname.h>

static CommonParameterManager * static_commonParameterManager = nil;

@implementation CommonParameterManager

+(CommonParameterManager*)shareManager
{
    @synchronized(self){
        if (!static_commonParameterManager) {
            static_commonParameterManager = [[CommonParameterManager alloc]init];
        }
    }
    return static_commonParameterManager;
}

+ (id)allocWithZone:(NSZone *)zone {
    @synchronized(self) {
        if (!static_commonParameterManager) {
            static_commonParameterManager = [super allocWithZone:zone];
            return static_commonParameterManager;
        }
    }
    return nil;
}

- (id)copyWithZone:(NSZone *)zone
{
    return self;
}

-(NSString*)ObtainUserAgent
{
    NSString * useragent = @"";
    
    return useragent;
}

-(NSDictionary*)ObtianCommonParameter
{
    NSMutableDictionary * commonparameterDic = [NSMutableDictionary dictionary];
    
    return commonparameterDic;
}

-(NSString*)deviceString
{
    struct utsname systemInfo;
    uname(&systemInfo);
    NSString *deviceString = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
    
    NSArray *modelArray = @[
                            
                            @"i386",
                            @"x86_64",
                            
                            @"iPhone1,1",
                            @"iPhone1,2",
                            @"iPhone2,1",
                            @"iPhone3,1",
                            @"iPhone3,2",
                            @"iPhone3,3",
                            @"iPhone4,1",
                            @"iPhone5,1",
                            @"iPhone5,2",
                            @"iPhone5,3",
                            @"iPhone5,4",
                            @"iPhone6,1",
                            @"iPhone6,2",
                            //iPhone 6 Plus的固件
                            @"iPhone7,1",
                            //iPhone 6的固件
                            @"iPhone7,2",
                            @"iPhone8,1",//6s
                            @"iPhone8,2",//6s +
                            
                            @"iPod1,1",
                            @"iPod2,1",
                            @"iPod3,1",
                            @"iPod4,1",
                            @"iPod5,1",
                            
                            @"iPad1,1",
                            
                            @"iPad2,1",
                            @"iPad2,2",
                            @"iPad2,3",
                            @"iPad2,4",
                            //iPad mini
                            @"iPad2,5",
                            @"iPad2,6",
                            @"iPad2,7",
                            //iPad 4
                            @"iPad3,1",
                            @"iPad3,2",
                            @"iPad3,3",
                            @"iPad3,4",
                            @"iPad3,5",
                            @"iPad3,6",
                            //iPad Air
                            @"iPad4,1",
                            @"iPad4,2",
                            @"iPad4,3",
                            //iPad Air 2
                            @"iPad5,3",
                            @"iPad5,4",
                            //iPad mini 2
                            @"iPad4,4",
                            @"iPad4,5",
                            @"iPad4,6",
                            //iPad mini 3
                            @"iPad4,7",
                            @"iPad4,8",
                            @"iPad4,9",
                            ];
    NSArray *modelNameArray = @[
                                
                                @"iPhone Simulator",
                                @"iPhone Simulator",
                                
                                @"iPhone 2G",
                                @"iPhone 3G",
                                @"iPhone 3GS",
                                @"iPhone 4",
                                @"iPhone 4",
                                @"iPhone 4",
                                @"iPhone 4S",
                                @"iPhone 5",
                                @"iPhone 5",
                                @"iPhone 5c",
                                @"iPhone 5c",
                                @"iPhone 5s",
                                @"iPhone 5s",
                                @"iPhone 6 Plus",
                                @"iPhone 6",
                                @"iPhone 6S",
                                @"iPhone 6S Plus",
                                
                                @"iPod Touch 1G",
                                @"iPod Touch 2G",
                                @"iPod Touch 3G",
                                @"iPod Touch 4G",
                                @"iPod Touch 5G",
                                
                                @"iPad",
                                
                                @"iPad 2",
                                @"iPad 2",
                                @"iPad 2",
                                @"iPad 2",
                                
                                @"iPad Mini",
                                @"iPad Mini",
                                @"iPad Mini",
                                
                                @"iPad 3",
                                @"iPad 3",
                                @"iPad 3",
                                
                                @"iPad 4",
                                @"iPad 4",
                                @"iPad 4",
                                
                                @"iPad Air",
                                @"iPad Air",
                                @"iPad Air",
                                
                                @"iPad Air 2",
                                @"iPad Air 2",
                                
                                @"iPad Mini2",
                                @"iPad Mini2",
                                @"iPad Mini2",
                                
                                @"iPad Mini3",
                                @"iPad Mini3",
                                @"iPad Mini3",
                                ];
    NSInteger modelIndex = - 1;
    NSString *modelNameString = nil;
    modelIndex = [modelArray indexOfObject:deviceString];
    if (modelIndex >= 0 && modelIndex < [modelNameArray count]) {
        modelNameString = [modelNameArray objectAtIndex:modelIndex];
    }
    
    if (modelNameString == nil) {
        modelNameString = deviceString;
    }
    
    return modelNameString;
}

@end
